package com.atguigu.tingshu.search.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * @author atguigu-mqx
 * @ClassName ThreadPoolExecutorConfig
 * @description: TODO
 * @date 2024年08月02日
 * @version: 1.0
 */
@Configuration
public class ThreadPoolExecutorConfig {

    @Bean
    public ThreadPoolExecutor threadPoolExecutor() {
        //  获取服务器cpu 核数 n指cpu核数
        int cpuCore = Runtime.getRuntime().availableProcessors();
        System.out.println("cpu核数：" + cpuCore);
        //  创建自定义线程池
        return new ThreadPoolExecutor(
                cpuCore,
                16,
                3,
                java.util.concurrent.TimeUnit.SECONDS,
                new java.util.concurrent.ArrayBlockingQueue<>(100),
                new java.util.concurrent.ThreadPoolExecutor.AbortPolicy()
        );

    }
}
